#ifndef EVENTLOOP_POLLER_H
#define EVENTLOOP_POLLER_H

#include "utility/chrono.h"
#include "utility/Noncopyable.h"

#include <vector>

class Channel;
class Eventloop;

class Poller {
public:
    using ChannelList = std::vector<Channel *>;

    Poller(Eventloop *loop);
    virtual ~Poller();

    // Poll the I/O events
    // Must be called in the loop thread;
    virtual Utility::timepoint poll(int timeoutMs, ChannelList *activeChannels) = 0;

    // Change the interested I/O events
    // Must be called in the loop thread
    virtual void update_channel(Channel *channel) = 0;

    // Remove the interested I/O events
    // Must be called in the loop thread
    virtual void remove_channel(Channel *channel) = 0;

    static Poller *new_defatult_poller(Eventloop *loop);
    
    void assert_in_loopthread();

private:
    NONCOPYABLE(Poller);

    Eventloop *_ownerLoop;
};


#endif